var express = require('express');
var router = express.Router();
var multer = require('multer');
var storage = multer.diskStorage({
  destination: function (req, file, cb) {
    cb(null, 'public/upload/');
  },
  filename: function (req, file, cb) {
    cb(null, file.originalname);
  }
});

var upload = multer({
  storage: storage
});
/* GET home page. */
router.get('/getUser', function (req, res, next) {
  console.log(req.query);
  // res.render('index', { title: 'Express' });
  res.json({
    errCode: 200,
    msg: '请求成功',
    data: {
      userName: '张三',
      phoneNumber: '1300000000'
    }
  })
});
router.post('/getData', function (req, res, next) {
  console.log(req.originalUrl)
  console.log(req.body.name);
  res.json({
    errCode: 200,
    msg: '请求成功',
    data: {
      userName: '张三',
      phoneNumber: '1300000000'
    }
  })
})
router.post('/upload', upload.single('file'),
  function (req, res, next) {
    console.log(req.body)
    console.log(req.file)
    res.json({
      code: 200,
      data: {
        fileName: req.file.filename,
        path: req.file.path
      }
    })
  })
module.exports = router;